package com.baosight.risk.common.aspects.factory;

import com.baosight.risk.service.system.entity.SysOperLog;
import com.baosight.risk.common.utils.SpringUtils;
import com.baosight.risk.api.system.ISysOperLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;
import java.util.TimerTask;

/**
 * 异步工厂（产生任务用）
 *
 * @author duanyongqiang
 */
@Slf4j
public class AsyncFactory {

    /**
     * 操作日志记录
     *
     * @param operLog 操作日志信息
     * @return 任务task
     */
    public static TimerTask recordOper(final SysOperLog operLog) {
        return new TimerTask() {
            @Override
            public void run() {
                log.info("系统操作日志保存处理" + operLog.toString());
                SpringUtils.getBean(ISysOperLogService.class).insert(operLog);
            }
        };
    }

    /**
     * 操作积分记录
     *
     * @param operLog 操作积分记录
     * @return 任务task
     */
    public static TimerTask integral(final SysOperLog operLog) {
        return new TimerTask() {
            @Override
            public void run() {
                log.info("系统操作日志保存处理" + operLog.toString());
//                SpringUtils.getBean(ISysOperLogService.class).insert(operLog);
            }
        };
    }

    /**
     * 操作日志记录(批量处理——工作流日志专用)
     *
     * @param operLogList 操作日志信息
     * @return 任务task
     */
    public static TimerTask batchRecordOper(final List<SysOperLog> operLogList) {
        return new TimerTask() {
            @Override
            public void run() {
                log.info("系统操作日志保存处理" + operLogList.toString());
                if (CollectionUtils.isNotEmpty(operLogList)) {
                    SpringUtils.getBean(ISysOperLogService.class).batchInsert(operLogList);
                }
            }
        };
    }

}
